package LeetCode.LeetCode2;

/**
 * 平衡二叉树
 * @author lumin
 * @date 2022/05/09 18:11
 **/
public class Num110 {
    public boolean isBalanced(TreeNode root) {
        if(root == null){
            return true;
        }
        return Math.abs(height(root.left) - height(root.right)) <= 1 && isBalanced(root.left) && isBalanced(root.right);
    }
    private int height(TreeNode root){
        if(root == null){
            return 0;
        }else{
            return Math.max(height(root.left),height(root.right)) + 1;
        }
    }
}